package cn.wolfcode.trip.base.service.impl;


import cn.wolfcode.trip.base.domain.News;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.mapper.NewsMapper;
import cn.wolfcode.trip.base.mapper.StrategyMapper;
import cn.wolfcode.trip.base.mapper.TravelMapper;
import cn.wolfcode.trip.base.query.CollectionQuery;
import cn.wolfcode.trip.base.service.ICollectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


@Service
public class CollectServiceImpl implements ICollectService{

    @Autowired
    private TravelMapper travelMapper;
    @Autowired
    private StrategyMapper strategyMapper;
    @Autowired
    private NewsMapper newsMapper;

    public PageInfo queryByUser(CollectionQuery qo) {
        int type = qo.getType();
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        if (type == 1) {  //如果type等于1就查出所有已收藏的游记
            List<Travel> list = travelMapper.selectTravel(qo);
            return new PageInfo<>(list);
        }else if (type == 2){  //如果type等于2就查出所有已收藏的攻略
            List<Strategy> list = strategyMapper.selectStrategy(qo);
            return new PageInfo<>(list);
        }else if (type == 3){  //如果type等于3就查出所有已收藏的日报
            List<News> list = newsMapper.selectNews(qo);
            return new PageInfo<>(list);
        }
        return null;
    }


    public int getNums(Long newsId, int type) {
        return newsMapper.getNums(newsId,type);
    }


    public int getPraiseNum(Long newsId, int type) {
        return newsMapper.getPraiseNum(newsId,type);
    }
}
